/*
 * VeriSimFrame.java
 * 
 * last update: 14.01.2010 by Stefan Saru
 * 
 * author:	Lucian Ghita Felix(felix@ulise.cs.pub.ro)
 *
 * Obs: N/A
 */


package ide;

import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import javax.swing.*;
import javax.swing.border.*;
import java.util.Enumeration;

import javax.swing.plaf.metal.*;



/**
 * This is the main container frame for the vide app
 *
 * @version 1.0
 */

@SuppressWarnings("serial")
public class VeriSimFrame extends JFrame {

	JMenuBar menuBar;
	public JDesktopPane desktop;
	JInternalFrame toolPalette;   // ce dracului e asta shi cine a pus-o aici?
	JCheckBoxMenuItem showToolPaletteMenuItem; //project
	Project theProject;
	ProjectView projectView;
	BookmarksView bookmarksView;
	StatusBar statusBar;
	FileHashtable fHash = new FileHashtable();
	RecentFiles recentFiles;
	RecentFiles recentProjects;
	JMenu recentFilesMenu;
	JMenu recentProjectsMenu;
	//ConsoleView consoleView;  //moved in Project.java 
	JToolBar mainToolbar;

	JMenu windowMenu;      

	static final Integer DOCLAYER = new Integer(5);
	static final Integer TOOLLAYER = new Integer(6);
	static final Integer HELPLAYER = new Integer(7);

	static final String ABOUTMSG = "vide IDE (c) 1999";

	public void refreshMRU(JMenu menu, RecentFiles rf, boolean MRUtype) {

		//MRUtype: true is recentFiles false if recent projects
		menu.removeAll();
		JMenuItem mi;
		for (int i = 1; i <= rf.number; i++) {
			if (MRUtype) {
				mi = menu.add(new MRFAction(i, rf.getName(i))); 
				mi.setMnemonic(("" + i).charAt(0));

			} else {
				mi = menu.add(new MRPAction(i, rf.getName(i)));   
				mi.setMnemonic(("" + i).charAt(0));

			}
		}
	}


	public VeriSimFrame() {
		super("vIDE - [no project]");
		vide.spl.showStatus("Creating vIDE main frame..");
		setBackground(UIManager.getColor("control"));
		statusBar = new StatusBar();

		desktop = new JDesktopPane();
		desktop. setMinimumSize(new Dimension(20, 20));

		theProject = new Project(this);
		theProject.sb = statusBar;
		//theProject.bf.pb = statusBar.pb;

		/*
    ButtonGroup indentGroup;   -- indentType:   none, default, smart
  JTextField tabField;        -- tabSize
  JTextField mrfField;   --- mrf
  JTextField mrpField;  --- mrp
  JCheckBox autosaveCheck;  --autosave
  JTextField autosaveField;   --autosaveTime
  JCheckBox backupCheck;      --autobackup
  JTextField undoField;       --undoSize
  ButtonGroup saveGroup;      -- saveType   unix, dos, auto
  ButtonGroup plafGroup;      -- plaf       metal, windows, motif, custom (?)
  ButtonGroup themeGroup;     -- theme      green, blue, bw
  JCheckBox saveBeforeRun     -- saveBeforeRun

		 */



		if (!fHash.isValid) {   //"prefs" file is invalid
			fHash.put("recentFiles", recentFiles = new RecentFiles());
			fHash.put("recentProjects", recentProjects = new RecentFiles());
			fHash.put("indentType","none");   
			fHash.put("tabSize", new Integer(2));
			fHash.put("mrf",new Integer(5));
			fHash.put("mrp",new Integer(5));
			fHash.put("autosave", new Boolean(false));
			fHash.put("autosaveTime", new Integer(5));
			fHash.put("autobackup", new Boolean(false));
			fHash.put("undoSize", new Integer(20));
			fHash.put("saveType", "auto");
			fHash.put("plaf", "metal");
			fHash.put("theme","blue"); 
			fHash.put("saveBeforeRun", new Boolean(true));
			fHash.put("loadLastProject", new Boolean(false));
			fHash.put("lastProject","none"); 

			//fHash.put("",);
		} else {
			recentFiles = (RecentFiles) fHash.get("recentFiles");
			recentProjects = (RecentFiles) fHash.get("recentProjects");


			//plaf selection

			String plaf = (String)fHash.get("plaf");
			String theme = (String)fHash.get("theme");

			if(plaf.equals("metal")) {
				try {
					UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
				}
				catch ( Exception e ) {
					System.out.println ("exception setting Look & Feel: " + e);

				}
				//javax.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme( new javax.swing.plaf.metal.DefaultMetalTheme());

				if(theme.equals("blue")) {
					javax.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme(new javax.swing.plaf.metal.DefaultMetalTheme());
				} else if(theme.equals("green")) {
					javax.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme(new CustomMetalTheme(fHash));
				} else if(theme.equals("bw")) {
					javax.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme(new CustomMetalTheme(fHash));
					//todo
					//javax.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme(new ContrastMetalTheme(fHash));
				} else {
					theProject.error("Unknown Metal Theme in prefs file. You should delete prefs file.");
				}

				//} else if(theme.equals("custom")) {




			} else if(plaf.equals("motif")) {
				try {
					UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
				}
				catch ( Exception e ) {
					System.out.println (" exception setting  Look & Feel: " + e);
				}

			} else {if(plaf.equals("windows")) {
				try {
					UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
				}
				catch ( Exception e ) {
					System.out.println (" exception setting  Look & Feel: " + e);
				}

			} else theProject.error("Look&Feel unknown in prefs file. Maybe you should delete prefs file.");
			}

			//theme selection


		}

		WaveViewFrame waveViewFrame = new WaveViewFrame(theProject);
		//theProject.waveViewFrame = waveViewFrame;   //todo
		//waveViewFrame.setVisible(true);


		final int inset = 50;
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		setBounds ( inset, inset, screenSize.width - inset*2, screenSize.height - inset*2 );



		JScrollPane scroller = new JScrollPane(desktop);

		vide.spl.showStatus("Creating vIDE main frame..");

		projectView = new ProjectView(theProject);
		projectView. setMinimumSize(new Dimension(20, 20));

		WatchView watchView= new WatchView(theProject);
		watchView.setMinimumSize(new Dimension(20, 20));


		ConsoleView consoleView = new ConsoleView(theProject);
		consoleView.setMinimumSize(new Dimension(20, 20));

		vide.spl.showStatus("Creating vIDE main frame..");
		JTabbedPane tabs = new JTabbedPane(SwingConstants.BOTTOM);

		tabs.addTab( "Project", null, projectView );
		tabs.addTab( "Watch", null, watchView );
		tabs.setMinimumSize(new Dimension(20, 40));

		vide.spl.showStatus("Creating vIDE main frame..");

		JSplitPane spliter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false, tabs, scroller); 
		spliter.setDividerSize(9);
		spliter.setOneTouchExpandable(true);

		JSplitPane spliter2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, false, spliter, consoleView); 
		spliter2.setDividerSize(9);
		spliter2.setOneTouchExpandable(true);

		//todo -> set minimum size for JComponents included in spliters.
		//     -> bug - scrollbars for desktop.  //nici MSVC nu are deci...
		//todo -> projectView in a tabbedpane with WatchView.

		getContentPane().add(spliter2);
		getContentPane().add(mainToolbar = buildToolbar(), BorderLayout.NORTH);
		getContentPane().add(statusBar, BorderLayout.SOUTH);
		vide.spl.showStatus("Creating vIDE main frame..");

		//theProject.bf = statusBar.pb;
		//statusBar.add(theProject.pb);
		//theProject.bf.go(null);      //todo
		buildMenus();
		//createBookmarksView();
		//createConsoleView();

		this.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				quit();
			}});

		UIManager.addPropertyChangeListener(new UISwitchListener((JComponent)getRootPane()));
		theProject.enableProjectActions(false);
		vide.spl.showStatus("Creating vIDE main frame..done");


		if( (((Boolean) fHash.get("loadLastProject")).booleanValue())  && (! ((String) fHash.get("lastProject")) .equals("none")) )
			theProject.openProject( (String) fHash.get("lastProject") );


	}

	protected void buildMenus() {
		vide.spl.showStatus("Creating menus..");  
		menuBar = new JMenuBar();
		menuBar.setOpaque(true);
		menuBar.setBackground(UIManager.getColor("control"));
		//menuBar.add(buildToolbar());

		JMenu file = buildFileMenu();
		//JMenu project = buildProjectMenu();  //this content was moved to fileMenu.
		JMenu edit = buildEditMenu();
		//JMenu views = buildViewsMenu();
		//todo: in urmatoarea versiune activam shi bookmarkurile
		//-deocamdata nu am chef sa vad de ce nu merge (5:03 am)
		JMenu proj = buildProjectMenu();
		JMenu sim = buildSimulationMenu();
		vide.spl.showStatus("Creating menus..");
		JMenu window = buildWindowMenu();

		JMenu help = buildHelpMenu();

		/*MetalTheme[] themes = {
      new DefaultMetalTheme(),
      new CustomMetalTheme(fHash),
      //new ContrastMetalTheme(fHash)
      };*/
		//unde dracu' se adauga listenerul pt meniul asta?
		//R: mai sus..
		//Menu themeMenu = new MetalThemeMenu("Theme", themes);

		menuBar.add(file);
		//menuBar.add(project);
		menuBar.add(edit);
		//menuBar.add(views);
		//menuBar.add(themeMenu);
		menuBar.add(proj);
		menuBar.add(sim);
		menuBar.add(window);
		menuBar.add(help);
		setJMenuBar(menuBar);
		vide.spl.showStatus("Done creating menus.");
		fHash.save();
	}

	private void addB(JToolBar t, AbstractAction a) {
		JButton b = t.add(a);
		b.setText(null);
		b.setToolTipText((String) a.getValue(AbstractAction.LONG_DESCRIPTION));
		b.setMargin(new Insets(0,0,0,0));
		b.setRolloverEnabled(true);
		//b.getAccessibleContext().setAccessibleName(a.name);
	}
	protected JToolBar buildToolbar() {

		vide.spl.showStatus("Creating toolbar..");
		JToolBar toolBar = new JToolBar();

		addB(toolBar, theProject.newAction);
		addB(toolBar, theProject.openAction);
		addB(toolBar, theProject.saveAction);
		addB(toolBar, theProject.saveAllAction);
		toolBar.addSeparator();
		addB(toolBar, theProject.cutAction);
		addB(toolBar, theProject.copyAction);
		addB(toolBar, theProject.pasteAction);
		addB(toolBar, theProject.deleteAction);
		toolBar.addSeparator();
		addB(toolBar, theProject.undoAction);
		addB(toolBar, theProject.redoAction);
		toolBar.addSeparator();

		JToggleButton waveViewToggleButton = new JToggleButton(new ImageIcon(vide.baseDir + "images/waveFrame.gif"));
		waveViewToggleButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (((JToggleButton.ToggleButtonModel)((JToggleButton)e.getSource()).getModel()).isSelected())
					theProject.waveViewFrame.setVisible(true);
				else
					theProject.waveViewFrame.setVisible(false);
			}});
		waveViewToggleButton.setMargin(new Insets(0,0,0,0));
		toolBar.add(waveViewToggleButton);
		toolBar.addSeparator();

		addB(toolBar, theProject.findPreviousAction);
		addB(toolBar, theProject.findAction);
		addB(toolBar, theProject.findNextAction);
		toolBar.addSeparator();
		toolBar.addSeparator();

		addB(toolBar, theProject.runAction);
		addB(toolBar, theProject.goAction);
		addB(toolBar, theProject.stepAction);
		addB(toolBar, theProject.timeUnitAction);

		addB(toolBar, theProject.stopAction);
		toolBar.addSeparator();
		/*    
    addB(toolBar, theProject.indentAction);
    addB(toolBar, theProject.unindentAction);

    toolBar.addSeparator();
		 */
		/*    JButton helpButton = new JButton(new ImageIcon(vide.baseDir + "images/help.gif"));
    helpButton.setToolTipText("Help");
    helpButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        openHelpWindow();
      }});
    helpButton.setMargin(new Insets(0,0,0,0));
    toolBar.add(helpButton);
		 */
		toolBar.addSeparator();


		addB(toolBar, theProject.previousWindowAction);
		addB(toolBar, theProject.nextWindowAction);

		toolBar.setFloatable(true);
		toolBar.putClientProperty( "JToolBar.isRollover", Boolean.TRUE );


		vide.spl.showStatus("Done creating toolbar..");
		return toolBar;
	}

	protected JMenu buildFileMenu() {
		vide.spl.showStatus("Creating File Menu..");

		JMenu file = new JMenu("File");
		file.setMnemonic('f');

		JMenuItem mi;
		mi = file.add(theProject.newAction);
		mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK, false));
		mi.setMnemonic(KeyEvent.VK_N);
		mi = file.add(theProject.openAction);
		mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK, false));
		mi.setMnemonic(KeyEvent.VK_O);
		mi = file.add(theProject.closeAction);
		mi.setMnemonic(KeyEvent.VK_C);
		mi = file.add(theProject.closeAllWindowsAction);
		mi = file.add(theProject.revertToSavedAction);

		file.add(new JSeparator());


		mi = file.add(theProject.saveAction);
		mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK, false));
		mi.setMnemonic(KeyEvent.VK_S);
		mi = file.add(theProject.saveAsAction);
		mi.setMnemonic(KeyEvent.VK_A);
		mi = file.add(theProject.saveAllAction);
		mi.setMnemonic(KeyEvent.VK_L);


		file.add(new JSeparator());

		mi = file.add(theProject.printAction);
		mi = file.add(theProject.printSetupAction);

		file.add(new JSeparator());

		recentFilesMenu = new JMenu("Recent Files");
		recentProjectsMenu = new JMenu("Recent Projects");

		refreshMRU(recentFilesMenu, recentFiles, true);
		refreshMRU(recentProjectsMenu, recentProjects, false);    

		file.add(recentFilesMenu);
		file.add(recentProjectsMenu);     

		file.add(new JSeparator());

		file.add(theProject.quitAction);
		vide.spl.showStatus("Done creating File Menu.");
		return file;
	}

	protected JMenu buildEditMenu() {
		vide.spl.showStatus("Creating Edit Menu..");
		JMenu edit = new JMenu("Edit");
		edit.setMnemonic('e');

		JMenuItem mi;
		mi = edit.add(theProject.undoAction);
		mi.setMnemonic(KeyEvent.VK_U);
		mi = edit.add(theProject.redoAction);
		mi.setMnemonic(KeyEvent.VK_R);
		edit.add(new JSeparator());

		mi = edit.add(theProject.cutAction);
		mi.setMnemonic(KeyEvent.VK_T);
		mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK, false));
		mi = edit.add(theProject.copyAction);
		mi.setMnemonic(KeyEvent.VK_C);
		mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK, false));
		mi = edit.add(theProject.pasteAction);
		mi.setMnemonic(KeyEvent.VK_P);
		mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK, false));
		mi = edit.add(theProject.deleteAction);
		mi.setMnemonic(KeyEvent.VK_D);
		mi = edit.add(theProject.selectAllAction);
		mi.setMnemonic(KeyEvent.VK_A);
		mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK, false));
		edit.add(new JSeparator());

		mi= edit.add(theProject.findAction);
		mi.setMnemonic(KeyEvent.VK_F);
		mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.CTRL_MASK, false));
		mi= edit.add(theProject.findPreviousAction);
		//mi.setMnemonic(KeyEvent.VK_R); //todo
		mi= edit.add(theProject.findNextAction);
		mi.setMnemonic(KeyEvent.VK_N);
		mi= edit.add(theProject.replaceAction);
		mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK, false));
		mi.setMnemonic(KeyEvent.VK_E);

		edit.add(new JSeparator());
		mi= edit.add(theProject.goToLineAction);
		mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, ActionEvent.CTRL_MASK, false));

		edit.add(new JSeparator());

		mi= edit.add(theProject.indentAction);
		//mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, ActionEvent.CTRL_MASK, false));

		mi= edit.add(theProject.unindentAction);
		//mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, ActionEvent.CTRL_MASK, false));


		edit.add(new JSeparator());


		JMenuItem prefs = new JMenuItem("Preferences...");
		prefs.setMnemonic(KeyEvent.VK_S);

		prefs.setIcon(theProject.emptyIcon);
		prefs.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				openPrefsWindow();
			}});

		edit.add(prefs);
		vide.spl.showStatus("Done creating Edit Menu.");
		return edit;
	}

	protected JMenu buildViewsMenu() {
		JMenu views = new JMenu("View");

		JMenuItem bookmarksView = new JMenuItem("Show Bookmarks View");


		bookmarksView.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				showBookmarksView();
			}});


		views.add(bookmarksView);
		return views;
	}

	protected JMenu buildSimulationMenu() {
		JMenu pmenu = new JMenu("Simulation");
		pmenu.setMnemonic('s');

		JMenuItem mi;
		mi = pmenu.add(theProject.runAction);
		mi.setMnemonic(KeyEvent.VK_R);
		mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, ActionEvent.CTRL_MASK, false));

		mi = pmenu.add(theProject.goAction);
		mi.setMnemonic(KeyEvent.VK_G);
		mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F6, ActionEvent.CTRL_MASK, false));

		mi = pmenu.add(theProject.stepAction);
		mi.setMnemonic(KeyEvent.VK_T);
		mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F7, ActionEvent.CTRL_MASK, false));

		mi = pmenu.add(theProject.timeUnitAction);
		mi.setMnemonic(KeyEvent.VK_U);
		mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F8, ActionEvent.CTRL_MASK, false));

		pmenu.add(new JSeparator());

		mi = pmenu.add(theProject.stopAction);
		mi.setMnemonic(KeyEvent.VK_S);
		mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F9, ActionEvent.CTRL_MASK, false));

		return pmenu;
	}

	protected JMenu buildProjectMenu() {
		JMenu pmenu = new JMenu("Project");
		pmenu.setMnemonic('p');

		JMenuItem mi;
		mi = pmenu.add(theProject.newProjectAction);
		mi.setMnemonic(KeyEvent.VK_T);
		mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK, false));

		mi = pmenu.add(theProject.openProjectAction);
		mi.setMnemonic(KeyEvent.VK_J);
		mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK, false));

		mi = pmenu.add(theProject.saveProjectAction);
		mi.setMnemonic(KeyEvent.VK_R);
		mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK, false));

		mi = pmenu.add(theProject.addFilesToProjectAction);
		mi.setMnemonic(KeyEvent.VK_I);
		mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK, false));

		mi = pmenu.add(theProject.removeCurrentFileFromProject);
		//mi.setMnemonic(KeyEvent.VK_I);
		//mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK, false));

		pmenu.add(new JSeparator());

		mi = pmenu.add(theProject.closeProjectAction);
		mi.setMnemonic(KeyEvent.VK_J);
		mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK, false));

		return pmenu;
	}

	protected JMenu buildWindowMenu() {
		vide.spl.showStatus("Creating Window Menu..");
		windowMenu = new JMenu("Window");
		windowMenu.setMnemonic('W');
		windowMenu.setMnemonic(KeyEvent.VK_W);
		windowMenu.add(theProject.closeWindowAction).setMnemonic('o');
		windowMenu.add(theProject.closeAllWindowsAction).setMnemonic(KeyEvent.VK_L);
		windowMenu.add(new JSeparator());
		windowMenu.add(theProject.nextWindowAction).setMnemonic('n');
		windowMenu.add(theProject.previousWindowAction).setMnemonic('p');
		windowMenu.add(new JSeparator());
		// in continuare se vor adauga runtime ferestrele deschise.
		vide.spl.showStatus("Done creating Window Menu.");
		return windowMenu;
	}



	protected JMenu buildHelpMenu() {
		vide.spl.showStatus("Creating Help Menu..");
		JMenu help = new JMenu("Help");
		JMenuItem about = new JMenuItem("About vide...");
		JMenuItem dump = new JMenuItem("Dump active threads");
		JMenuItem openHelp = new JMenuItem("Open Help Window");

		about.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				showAboutBox();
			}});

		dump.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dump();
			}});


		openHelp.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				openHelpWindow();
			}});


		help.add(openHelp);
		help.add(dump);
		help.add(about);
		vide.spl.showStatus("Done creating Help Menu..");
		return help;
	}



	protected void showBookmarksView() {
		try {
			bookmarksView.setSelected(true);
		} catch (Exception e) {
			System.out.println(e.toString());
		}
	}



	public void quit() {
		//ar trebui sa verifice daca sunt necesare salvari
		//todo
		System.out.println("Exiting vIDE");
		if(theProject.isValid) fHash.put("lastProject", theProject.name + ".vpr");
		else fHash.put("lastProject","none");
		fHash.save();
		VeriSimDocumentFrame temp;
		for (Enumeration e = theProject.editors.elements() ; e.hasMoreElements() ;) {
			temp = (VeriSimDocumentFrame)e.nextElement();
			temp.dispose();

		}

		theProject.closeProject();
		System.exit(0);
	}


	public void openHelpWindow() {
		JInternalFrame help = new HelpWindow();
		desktop.add(help, HELPLAYER);
		try {
			help.setSelected(true);
		} catch (java.beans.PropertyVetoException e2) {}
	}

	public void showAboutBox() {
		//JOptionPane.showMessageDialog(this, ABOUTMSG);
		AboutDialog ad = new AboutDialog(this);
		ad.show();
	}

	public void openPrefsWindow() {
		VeriSimPrefs dialog = new VeriSimPrefs(this);
		dialog.show();
	}

	public void createConsoleView() {
		//consoleView = new ConsoleView(theProject);
	}

	public void createBookmarksView() {
		bookmarksView = new BookmarksView(theProject);
		desktop.add(bookmarksView, TOOLLAYER);
		try {
			bookmarksView.setSelected(true);
		} catch (java.beans.PropertyVetoException e2) {}
	}

	public void dump() {
		theProject.simulationThreadGroup.list();
	}



	@SuppressWarnings("serial")
	class MRPAction extends AbstractAction {
		private String fileName;
		public MRPAction(int i, String _fileName) {

			super(i + " " + _fileName);
			fileName = _fileName;
			setEnabled(true);
		}

		public void actionPerformed(ActionEvent e) {
			theProject.openProject(fileName);
		}
	}

	@SuppressWarnings("serial")
	class MRFAction extends AbstractAction {
		private String fileName;
		public MRFAction(int i, String _fileName) {

			super(i + " " + _fileName);
			fileName = _fileName;
			setEnabled(true);
		}

		public void actionPerformed(ActionEvent e) {
			theProject.openFile(fileName);
		}
	}
	/*


  class SaveWaveSetAction extends AbstractAction {
    public SaveWaveSetAction() {
      super("Save WaveSet");setEnabled(false);
      putValue(SMALL_ICON, new ImageIcon(vide.baseDir + "images/timeUnit.gif"));
      putValue(LONG_DESCRIPTION, "Saves the current WaveSet");
    }
    public void actionPerformed(java.awt.event.ActionEvent event) {
      waveViewFrame.saveWaveSet();
    }
  }

	 */




	@SuppressWarnings("serial")
	class StatusBar extends JPanel {
		private JLabel label;
		private JLabel label2;
		public JProgressBar pb;

		public StatusBar() {
			super();
			vide.spl.showStatus("Creating Status Bar..");
			label = new JLabel("");
			label2 = new JLabel("Ln ***, Col ***");
			pb = new JProgressBar();
			pb.setMaximum(60);
			pb.setMinimum(0);
			pb.setPreferredSize(new Dimension(60, 15));
			setLayout(new BorderLayout());
			add(label, BorderLayout.CENTER);
			add(label2, BorderLayout.EAST);
			validate();
			vide.spl.showStatus("Done creating Status Bar.");
		}

		public final void setLnCol(int l, int c) {
			label2.setText("Ln " + l + ", Col " + c);
		}

		public final void printStatus(String statusText) {
			label.setText(statusText);
			label.invalidate();
		}

		public final void initPBar() {
			add(pb, BorderLayout.WEST);
			pb.setMaximum(0);
			pb.invalidate();
			revalidate();
		}

		public final void adjustPBar(int max, String text) {
			printStatus(text);
			pb.setMaximum(max);
			pb.setValue(0);
			pb.invalidate();
		}

		public final void donePBar() {
			remove(pb);
			revalidate();
		}

		public final void incPBar() {
			incPBar(1);
		}

		public final void incPBar(int amount) {
			pb.setValue(pb.getValue() + amount);
			pb.invalidate();
		}
	}
}


